package com.shut.vehicle.util;


import cn.hutool.core.util.StrUtil;
import com.shut.vehicle.exception.ServiceException;
import org.apache.commons.lang3.StringUtils;
/**
 * @author 卢斌
 */
public class StrParamUtil {

    private static String into (String emptyStr, String body, Object... arg) {
        Object[] params = arg.clone();
        if (params == null) {
            params = new Object[0];
        }
        int paramNum = StringUtils.countMatches(body,"{}");
        if (paramNum != params.length) {
            throw new ServiceException("字符拼接失败");
        }
        for (Object eachParam : params) {
            String replaceValue;
            if (eachParam != null) {
                replaceValue = String.valueOf(eachParam);
            } else {
                replaceValue = emptyStr;
            }
            body = body.replaceFirst("\\{}", replaceValue);
        }
        return body;
    }

    public static String into(String body, Object... arg) {
        return into(com.aliyun.core.utils.StringUtils.EMPTY, body, arg);
    }

    public static String intoWriteNull(String body, Object... arg) {
        return into(StrUtil.NULL, body, arg);
    }


}
